﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using SPIWareMVVM.ViewModels;
using DataAccess;
using System.Collections.ObjectModel;
using System.Windows;

namespace SPIWareMVVM.Views.Commands
{
    public class ShowCustomerMaterialListCommand : BaseCommand
    {
        ApplicationViewModel _sender { get; set; }

        public ShowCustomerMaterialListCommand(BaseViewModel sender) : base(sender) { }

        public override void Execute(object parameter)
        {

            MaterialList list = null;
            if (parameter != null) list = (MaterialList)parameter;
            if (list != null)
            {
                if (mainWindow == null) mainWindow = (Window1)Window.GetWindow((MaterialList)list);
                ApplicationData.ClearAllExcept(new List<Type> { typeof(Customer) });
                mainWindow.HideLists();
                if (ApplicationData.SelectedCustomer != null)
                {
                    list.lbMaterials.ItemsSource = ApplicationData.SelectedCustomer.CustomerParts;
                    list.Visibility = Visibility.Visible;
                    list.editMaterial.Visibility = Visibility.Visible;
                }
            }
            //WorkOrderList list = null;
            //if (parameter != null) list = (WorkOrderList)parameter;

            //if (list != null && ApplicationData.SelectedCustomer != null)
            //{
            //    if (mainWindow == null) mainWindow = (Window1)Window.GetWindow((WorkOrderList)list);
            //    mainWindow.HideLists();

            //    list.lbWorkOrders.ItemsSource = null;
            //    list.lbWorkOrders.ItemsSource = ApplicationData.SelectedCustomer.WorkOrders;
            //    list.lbWorkOrders.SelectedIndex = -1;

            //    list.cboParts.ItemsSource = null;
            //    list.cboParts.ItemsSource = ApplicationData.SelectedCustomer == null
            //        ? ApplicationData.ocParts
            //        : ApplicationData.localParts();

            //    list.cboCustomers.ItemsSource = ApplicationData.ocCustomers;

            //    list.lbWorkOrders.SelectedIndex = -1;

            //    mainWindow.customersList.Visibility = Visibility.Visible;
            //    mainWindow.workOrdersList.Visibility = Visibility.Visible;
            //}
            //else list.lbWorkOrders.ItemsSource = ApplicationData.ocWorkOrders;


        }
    }
}
